<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2011
 */

/**
 *
 *
 */
class ExcHtml extends CHtml {
	public static function activeDateField($model,$attribute,$htmlOptions=array(), $labels)
	{
		// SET UP ARRAYS OF OPTIONS FOR DAY, MONTH, YEAR
		$x = 1;
		$dayOptions = array('0'=> '-');
		while ($x < 31)
		{
			$dayOptions[$x] = $x;
			$x++;
		}

		$monthOptions = array(
				'0'=> '-',
		        '1'=>'1',
		        '2'=>'2',
		        '3'=>'3',
		        '4'=>'4',
		        '5'=>'5',
		        '6'=>'6',
		        '7'=>'7',
		        '8'=>'8',
		        '9'=>'9',
		        '10'=>'10',
		        '11'=>'11',
		        '12'=>'12',
		);

		$yearOptions = array('0'=>' - ');
		$x = 1901;
		while ($x < 2030)
		{
			$yearOptions[$x] = $x;
			$x++;
		}


		parent::resolveNameID($model,$attribute,$htmlOptions);

		if ($model->$attribute != '0000-00-00' && isset($model->$attribute))
		{
			// intval removes leading zero
			$day = intval(date('j',strtotime($model->$attribute)));
			$month = intval(date('m',strtotime($model->$attribute)));
			$year = intval(date('Y',strtotime($model->$attribute)));
		} else
		{
			// DEFAULT TO 0 IF THERE IS NO DATE SET
			$day = 0;
			$month = 0;
			$year = 0;
		}


		$return = $labels['date'];
		$return	.= parent::dropDownList($htmlOptions['name'].'[day]', $day,$dayOptions);
		$return .= $labels['month'];
		$return .= parent::dropDownList($htmlOptions['name'].'[month]', $month,$monthOptions);
		$return .= $labels['year'];
		$return .= parent::dropDownList($htmlOptions['name'].'[year]', $year,$yearOptions);
		return $return;
	}
}
?>